package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Tag;
import cn.wolfcode.trip.base.mapper.TagMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITagService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagServiceImpl implements ITagService {
    @Autowired
    private TagMapper tagMapper;

    /**
     * 1.直接根据攻略id查询其下系统推荐的标签
     * 目前没有额外业务
     * @param strategyId
     * @return
     */
    public List<Tag> listByStrategyId(Long strategyId) {
        return tagMapper.selectByStrategyId(strategyId);
    }

    /**
     * 2.保存攻略评论的同时保存其下的标签
     * @param entity
     */
    public void save(Tag entity) {
        tagMapper.insert(entity);
    }

    public PageInfo<?> query(QueryObject qo) {

        return null;
    }

    public void update(Tag entity) {

    }

    public void saveOrUpdate(Tag entity) {
        if (entity.getId() == null) {
            tagMapper.insert(entity);
        } else {
            tagMapper.updateByPrimaryKey(entity);
        }
    }

    public List<Tag> list() {
        return tagMapper.selectAll();
    }
}
